#include <iostream>
#include <string>
#include <limits>

using std::cout;
using std::endl;
using std::cerr;
using std::cin;
using std::string;

void printStreamStatus()
{
    cout << "cin.badbit = " << cin.bad() << endl
         << "cin.failbit = " << cin.fail() << endl
         << "cin.eofbit = " << cin.eof() << endl
         << "cin.goodbit = " << cin.good() << endl;
}

void test()
{
    int number = 0;
    printStreamStatus();
    cin >> number;
    printStreamStatus();
    cin.clear();//重置流的状态
    /* cin.ignore(1024, '\n');//清空缓冲区 */
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//清空缓冲区
    cout << "number = " << number << endl;
    printStreamStatus();

    string word;
    cin >> word;
    cout << "word = " << word << endl;
}

void test2()
{
    int number = 0;
    //真值表达式while(cin)
    //真值表达式转换为逗号表达式
    while(cin >> number, !cin.eof())
    {
        if(cin.bad())//不能恢复的系统级别的错误
        {
            cerr << "The stream is bad" << endl;
            return ;
        }
        else if(cin.fail())//可以恢复的错误
        {
            cin.clear();//重置流的状态
            cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//清空缓冲区
            cout << "pls input int data" << endl;
        }
        else
        {
            cout << "number = " << number << endl;
        }
    }
}

int main(int argc, char **argv)
{
    test2();
    return 0;
}

